package com.filldream.fastboot.common.entity;

/**
 * @author RickSun
 * @Description 错误码枚举类
 * @version 2.0
 * @date 2019-03-22 15:56
 **/
public enum ErrorCode {

    /**
     * 错误返回说明:
     * 1、200~1999代表系统错误
     * 2、2000~2999代表业务错误
     * 3、3000~3999代表第三方错误
     **/

    SUCCESS(200,"ok.","成功"),
    EMPTY_RESULT(200,"Ok,But empty","成功"),
    FAIL(202,"fail.","失败"),
    NO_LOGIN(401,"Login failed, please re-login.","登陆验证失败，请重新登陆"),
    REPEAT_REQUEST_ERR(403, "repeat request err", "操作过于频繁，请稍后重试"),
    REQUEST_NOT_EXISTS(404, "request_not_exists", "请求路径不存在"),
    DUPLICATE_ERR(409 , "Duplicate error", "请勿输入重复的值%s"),
    PARAM_ERR(412 ,"Parameter error.","参数错误%s"),
    PARAM_ERR_F(417 ,"Parameter error.","参数错误%s"),
    SERVER_BUSY(500,"The system is busy. Please try again later.","系统繁忙，请稍后再试%s"),
    DB_ERR(501,"Database exception.","数据异常"),
    HTTP_REQUEST_ERR(505, "Request method error", "HTTP请求错误:%s"),
    BASE_ERR(555, "BASE_ERR", "温馨提示%s"),
    RESOURCE_UPLOAD_ERROR(1007, "RESOURCE_UPLOAD_ERROR", "上传失败,请重试%s"),
    IMG_ZIP_ERROR(1008, "IMG_ZIP_ERROR", "图片压缩失败"),
    RES_TYPE_DENY(1009, "RES_TYPE_DENY", "文件类型不合法%s"),
    IMG_TYPE_NOT_SUPPORT(1010, "IMG_TYPE_NOT_SUPPORT", "图片格式不支持"),
    DOWNLOAD_ERR(1011, "Download err", "下载失败%s"),
    AUTH_ERR(9999,"Authentication failure.","鉴权异常%s"),
    SERVER_CMD_ERR(9998,"The server command not found","该服务器不支持%s"),

    //基本业务相关错误
    TELEPHONE_EXIT(2001,"The current phone has been bound.","该手机号已被绑定"),
    USER_NOT_EXIST(2002,"User not exist","当前用户不存在"),
    USER_EXIST(2003,"User is exist","当前用户已存在"),
    REGISTER_ERR(2004,"register_err.","注册失败，请检查后重试"),
    PASSWORD_ERROR(2005,"Account or password error.","账号或密码错误"),
    CHECKCODE_ERR(2006,"Check code is error or timed","验证码错误或已失效"),
    NO_BIND_WECHAT_ERR(2007,"Sorry, your credit is running low.","尚未绑定微信"),
    DELETE_SUBMENU_ERR(2008,"Sorry,Please delete the submenu first","请先删除子菜单%s"),
    MSG_TEMPLATE_ERR(2009, "Msg template error", "短信模板错误%s"),

    //第三方异常
    WECHAT_BASE_ACCESSTOKEN_ERR(3001,"Wechat Base AccessToken failed.","微信授权失败%s"),
    WECHAT_AUTH_ERR(3002,"Wechat authorization failed.","微信授权失败%s"),
    WECHAT_OPENID_ERR(3003,"Wechat authorization openid failed.","微信用户授权失败(openid)%s"),
    WECHAT_ACCESSTOKEN_ERR(3004,"Wechat authorization AccessToken failed.","微信用户授权失败(AccessToken)%s"),
    WECHAT_USERINFO_ERR(3005,"Wechat authorization userInfo failed.","获取微信用户信息失败%s"),
    WECHAT_MSGTEMPLATE_ERR(3006,"Wechat msg_template err.","微信模板错误%s"),
    WECHAT_PAY_ERR(3101,"Sorry, WechatPay is not successed.","微信支付失败%s"),
    ALI_PAY_ERR(3201,"Sorry, Alipay is not successed.","支付失败%s"),

    ;

    /** 错误码  */
    private int code;

    /** 返回信息  */
    private String msg;

    /** 返回信息备份，用于msg异常情况的问题 **/
    private String msgBackUp;

    /** 返回信息  */
    private String enmsg;


    private ErrorCode(int code, String enmsg,String msg){
        this.code = code ;
        this.msg = msg ;
        this.msgBackUp = msg;
        this.enmsg =enmsg;
    }


    ErrorCode(String msg){
        this.code = -2;
        this.msg = msg;
        this.msgBackUp = msg;
        this.enmsg = "Business error.";
    }


    public String getString(){
        return "code:" + this.code + " enmsg:" + this.getEnMsg() + " msg:" + this.getMsg() ;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return this.msg;
    }

    /**
     * 替换占位符
     * @param content   自定义信息
     * @return
     */
    public ErrContent reMsg(String content) {
        ErrContent errContent = new ErrContent();
        errContent.setErrorCode( this );
        errContent.reMsg(content);
        return errContent;
    }

    /**
     * 删除占位符即用空串替换占位符
     * @return
     */
    public ErrContent reMsg() {
        return reMsg("");
    }

    /**
     * 自定义信息
     * 保留原来的ErrorCode.code
     * 自定义ErrorCode.msg
     * @param text  自定义信息
     * @return
     */
    public ErrContent diyMsg(String text) {
        ErrContent errContent = new ErrContent();
        errContent.setErrorCode( this );
        errContent.setContent(text);
        return errContent;
    }


    public void setMsg(String msg) {
        this.msg = msg;
    }

    public String getEnMsg() {
        return enmsg;
    }


}
